import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../components/Layout.vue';
import store from '@/store';
import { findSector } from "@/api/sector";

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [{
        path: '/',
        component: Layout,
        children: [
            {
                path: '',
                name: 'Index',
                component: () => import("@/views/index/index.vue")
            },
            {
                path: 'tuyere',
                name: 'Tuyere',
                component: () => import("@/views/tuyere/index.vue")
            },{
                path: 'sector',
                name: 'Sector',
                component: () => import("@/views/sector/index.vue")
            },{
                path: 'cartesian',
                name: 'Cartesian',
                component: () => import("@/views/cartesian/index.vue")
            },{
                path: 'line',
                name: 'Line',
                component: () => import("@/views/line/index.vue")
            },{
                path: 'test',
                name: 'Test',
                component: () => import("@/views/test/index.vue")
            },{
                path: 'calendar',
                name: 'Calendar',
                component: () => import("@/views/calendar/index.vue")
            },{
                path: 'board',
                name: 'Board',
                component: () => import("@/views/board/index.vue")
            }
        ]
    }]
})


router.beforeEach((to, from, next) => {

    findSector().then(res=>{
        
        store.dispatch('app/setSectors',res.data.rows);
        next();
    })


})


export default router
